package com.itheima.demo08;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Demo001 {

    public static void main(String[] args) {

        //public static Collector toList()把元素收集到List集合中
        //public static Collector toSet()把元素收集到Set集合中
        //public static Collector toMap(Function keyMapper ,Function valueMapper)把元素收集到Map集合中

        ArrayList<Integer> arrayList = new ArrayList<>();

        arrayList.add(12);
        arrayList.add(23);
        arrayList.add(34);
        arrayList.add(45);
        arrayList.add(56);
        arrayList.add(67);

        Stream<Integer> integerStream = arrayList.stream().filter(s -> s >= 34);

        /*List<Integer> collect = integerStream.collect(Collectors.toList());

        collect.forEach(s-> System.out.println(s));*/

        Set<Integer> collect = integerStream.collect(Collectors.toSet());

        collect.forEach(s-> System.out.println(s));


        System.out.println("-----------------------------------------");


        ArrayList<String> arrayList1 = new ArrayList<>();

        arrayList1.add("小脑斧,12");
        arrayList1.add("小凶许,23");
        arrayList1.add("小兔几,11");
        arrayList1.add("小王八,15");

        Stream<String> stringStream = arrayList1.stream().filter(s -> {
            String[] split = s.split(",");
            String s1 = split[1];
            int i = Integer.parseInt(s1);

            if (i > 12) {
                return true;
            } else {
                return false;
            }
        });

        Map<String, Integer> collect1 = stringStream.collect(Collectors.toMap(s -> s.split(",")[0],
                s -> Integer.parseInt(s.split(",")[1])));

        collect1.forEach((s,s1)-> System.out.println(s+"-----"+s1));

    }

}
